package com.hwl.oss.controller;

import com.hwl.commonutils.result.RespBean;
import com.hwl.oss.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@Api(tags = "阿里云文件管理")
@RestController
@RequestMapping("/admin/oss")
public class FileController {

    @Resource
    private FileService fileService;

    @ApiOperation("阿里云文件上传")
    @PostMapping("upload")
    public RespBean upload(@RequestParam("file") MultipartFile file,
                           @RequestParam("module") String module) {
        return RespBean.ok().data(fileService.uploadAvatar(file, module));
    }

    @ApiOperation("文件删除")
    @DeleteMapping("remove")
    public RespBean removeFile(@RequestBody String url) {
        fileService.removeFile(url);
        return RespBean.ok().message("文件删除成功！");
    }

}
